<?php

require_once('util.php');

class Turma extends CI_Controller{

	public function __construct() {
		parent::__construct();	
		$this->load->model('turma_model');
	}

	public function cadastrar(){
		
		$data['escolas']='';
		$data['etapas']='';
		
		$query = $this->db->get('escolas');		
		foreach ($query->result() as $row)
		{
			$data['escolas'].= '<option value="'. $row->id .'">'.$row->nome.'</option>';
		}
		$query = $this->db->get('etapas');
		foreach ($query->result() as $row)
		{
			$data['etapas'].= '<option value="'. $row->id .'">'.$row->nome.'</option>';
		}
		Util::show($this, 'turma/cadastrar', $data);
	}

	public function salvar(){
		$this->turma_model->salvar();	
		echo 'ok';
	}

	public function atualizar(){
		$this->turma_model->atualizar();	
		echo 'ok';
	}	

	public function listar(){
		$data['escolas']='';
		$data['etapas']='';
		
		$query = $this->db->get('escolas');		
		foreach ($query->result() as $row)
		{
			$data['escolas'].= '<option value="'. $row->id .'">'.$row->nome.'</option>';
		}
		$query = $this->db->get('etapas');
		foreach ($query->result() as $row)
		{
			$data['etapas'].= '<option value="'. $row->id .'">'.$row->nome.'</option>';
		}
		Util::show($this, 'turma/listar', $data);
	}

	public function remover(){
		$this->turma_model->delete();
		echo 'Usuário removido com sucesso';
	}

	public function consultar(){
		$data['turmas'] = $this->turma_model->listar();
		$this->load->view('turma/turma_table', $data);	
	}

	public function show_info_json(){
		$data['turma'] = $this->turma_model->consultar_por_id();
		echo json_encode($data['turma']);
	}


}

?>